import formInfo from '@ohos.app.form.formInfo';
import formBindingData from '@ohos.app.form.formBindingData';
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formProvider from '@ohos.app.form.formProvider';

export default class EntryFormAbility extends FormExtensionAbility {
  onAddForm(want) {
    // Called to return a FormBindingData object.

    let formData = {};
    return formBindingData.createFormBindingData(formData);
  }

  onCastToNormalForm(formId) {
    // Called when the form provider is notified that a temporary form is successfully
    // converted to a normal form.
  }

  onUpdateForm(formId) {
    // Called to notify the form provider to update a specified form.
    let str:string[] = ["桃花","财运","狗屎运","不宜外出","血光之灾"];
    let index = Math.round(Math.random()*(str.length-1));
    let formData = {
      title:str[index]
    };
    let formInfo = formBindingData.createFormBindingData(formData);
    // console.log("message"+JSON.stringify(message));
    formProvider.updateForm(formId, formInfo)
  }

  onChangeFormVisibility(newStatus) {
    // Called when the form provider receives form events from the system.
  }

  onFormEvent(formId, message) {
    // Called when a specified message event defined by the form provider is triggered.
    let str:string[] = ["桃花","财运","狗屎运","不宜外出","血光之灾"];
    let index = Math.round(Math.random()*(str.length-1));
    let formData = {
      title:str[index]
    };
    let formInfo = formBindingData.createFormBindingData(formData);

    console.log("message"+JSON.stringify(message));
    formProvider.updateForm(formId, formInfo)
  }

  onRemoveForm(formId) {
    // Called to notify the form provider that a specified form has been destroyed.
  }

  onAcquireFormState(want) {
    // Called to return a {@link FormState} object.
    return formInfo.FormState.READY;
  }
};